package com.gem.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gem.domain.ClassInfo;
import com.gem.domain.ClassInfoAPI;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 玲
 * @Description:
 * @create 2019-11-06 15:54
 * @Modified By:
 */
public class Test2Json {
    public static void main(String[] args) {
        Map<String,  Boolean> map = new HashMap<>();
//        List<ClassInfo> list = new ArrayList<>();
//        ClassInfo classInfo = new ClassInfo();
//        classInfo.setMName("村上春树");
//        ClassInfo classInfo2 = new ClassInfo();
//        classInfo2.setMName("按时大苏打");
//        ClassInfo classInfo3 = new ClassInfo();
//        classInfo3.setMName("啊大苏打");
//        list.add(classInfo);
//        list.add(classInfo2);
//        list.add(classInfo3);
//        map.put("class",classInfo);
//        ObjectMapper mapper = new ObjectMapper();
//        String json = null;
//        try {
//            json = mapper.writeValueAsString(map);
//        } catch (JsonProcessingException e) {
//            e.printStackTrace();
//        }
//        System.out.println(json);


        ClassInfoAPI classinfo = new ClassInfoAPI();
        classinfo.setId(49);
//        classinfo.setCId("班级测试接口");
//        classinfo.setMName("班主任");
//        classinfo.setTName("老师改");
        HttpHeaders headers = new HttpHeaders();
        boolean httpPost = HttpPost(49, headers);
        System.out.println("main-->"+httpPost);
    }
     public static boolean HttpPost(Integer info, HttpHeaders headers){
//        String url = "http://10.40.1.27:8080/crm/factory/deleteStudent";
//         String url = "http://127.0.0.1:8080/crm/factory/addClass";
//         String url = "http://127.0.0.1:8080/crm/factory/updateClass";
         String url = "http://127.0.0.1:8080/crm/factory/deleteClass";
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        RestTemplate rt = new RestTemplate();
        HttpEntity<Integer> id =new HttpEntity<>(info);
        rt.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        ResponseEntity<Map> res = rt.postForEntity(url, id, Map.class);
        System.out.println("HttpPost-->"+res.getBody());
        return (boolean) res.getBody().get("0");
    }
}
